// database/migrations/2025112401_add_bank_transaction_details.js
'use strict';

module.exports = {
  up: async (queryInterface, Sequelize) => {
    // 添加银行流水详细信息字段
    await queryInterface.addColumn('bank_transactions', 'bank_name', {
      type: Sequelize.STRING(200),
      allowNull: true,
      comment: '银行名称'
    });
    
    await queryInterface.addColumn('bank_transactions', 'currency', {
      type: Sequelize.STRING(50),
      allowNull: true,
      comment: '币种'
    });
    
    await queryInterface.addColumn('bank_transactions', 'channel', {
      type: Sequelize.STRING(50),
      allowNull: true,
      comment: '交易渠道'
    });
    
    await queryInterface.addColumn('bank_transactions', 'fee', {
      type: Sequelize.DECIMAL(12, 2),
      allowNull: true,
      defaultValue: 0,
      comment: '手续费'
    });
    
    await queryInterface.addColumn('bank_transactions', 'account_name', {
      type: Sequelize.STRING(200),
      allowNull: true,
      comment: '己方账户名称'
    });
    
    await queryInterface.addColumn('bank_transactions', 'account_number', {
      type: Sequelize.STRING(100),
      allowNull: true,
      comment: '己方账户号码'
    });
    
    // 添加索引
    await queryInterface.addIndex('bank_transactions', ['bank_name'], {
      name: 'idx_bank_transactions_bank_name'
    });
    
    await queryInterface.addIndex('bank_transactions', ['currency'], {
      name: 'idx_bank_transactions_currency'
    });
    
    await queryInterface.addIndex('bank_transactions', ['channel'], {
      name: 'idx_bank_transactions_channel'
    });
  },

  down: async (queryInterface, Sequelize) => {
    // 删除索引
    await queryInterface.removeIndex('bank_transactions', 'idx_bank_transactions_bank_name');
    await queryInterface.removeIndex('bank_transactions', 'idx_bank_transactions_currency');
    await queryInterface.removeIndex('bank_transactions', 'idx_bank_transactions_channel');
    
    // 删除字段
    await queryInterface.removeColumn('bank_transactions', 'bank_name');
    await queryInterface.removeColumn('bank_transactions', 'currency');
    await queryInterface.removeColumn('bank_transactions', 'channel');
    await queryInterface.removeColumn('bank_transactions', 'fee');
    await queryInterface.removeColumn('bank_transactions', 'account_name');
    await queryInterface.removeColumn('bank_transactions', 'account_number');
  }
};